home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / IMDB.ifs < prev    next >
Encoding:
Text File  |  2005-02-02  |  21.7 KB  |  684 lines

  1. // GETINFO SCRIPTING
  2. // IMDB (US) import - click "Editor" tab to change options
  3.  
  4. {
  5.    To change the options, go to the "GetOption"
  6.    and "CanSetField" functions
  7. }
  8.  
  9. (***************************************************
  10.  *  Movie importation script for:                  *
  11.  *      IMDB (US), http://us.imdb.com              *
  12.  *                                                 *
  13.  *  (c) 2002-2005 Antoine Potten                   *
  14.  *                          software@antp.be       *
  15.  *                                                 *
  16.  *  For use with Ant Movie Catalog 3.4.3           *
  17.  *  www.antp.be/software/moviecatalog              *
  18.  *                                                 *
  19.  *  Based on the script rewritten for version 3.5  *
  20.  *  Which was based on the script made for         *
  21.  *  version 3.3.x / 3.4.x by                       *
  22.  *  Antoine Potten, Danny Falkov, Kai Blankenhorn, *
  23.  *  lboregard, Ork, Trekkie, Youri Heijnen         *
  24.  *                                                 *
  25.  *  This program is free software; you can         *
  26.  *  redistribute it and/or modify it under the     *
  27.  *  terms of the GNU General Public License as     *
  28.  *  published by the Free Software Foundation;     *
  29.  *  either version 2 of the License, or (at your   *
  30.  *  option) any later version.                     *
  31.  ***************************************************)
  32.  
  33. program IMDB;
  34.  
  35. // ***** Here you can change the options of the script *****
  36.  
  37. function GetOption(OptName: string): Integer;
  38. begin
  39.   case OptName of
  40.     'ImageKind': Result := 2;
  41.         {
  42.           0=No image
  43.           1=IMDB small image, from the main movie page
  44.           2=IMDB large image if found easily, else small image
  45.           3=First search for Amazon large image, then IMDB large one, then IMDB small image if other failed
  46.           4=First search for Amazon large image, then directly take IMDB small image if the first one failed
  47.           5=IMDB large image if found easily, else search for Amazon large image, then take IMDB small image if others failed
  48.         }
  49.     'BatchMode': Result := 0;
  50.         {
  51.           0=Normal working mode, prompts user when needed
  52.           1=Does not display any window, takes the first movie found
  53.         }
  54.     'PopularSearches': Result := 1;
  55.         {
  56.           0=Do not use the popular searches page, directly show full search results
  57.           1=Show popular searches first, I'll click on "Find more" if needed
  58.         }
  59.     'ActorsLayout': Result := 0;
  60.         {
  61.           0=Only actor names, separated by commas
  62.           1=Only actor names, separated by linebreaks
  63.           2=Actors names with character names between parenthesis separated by commas
  64.           3=Actors names with character names between parenthesis separated by linebreaks
  65.           4=Actor names like on IMDB page, with "...." and separated by linebreaks
  66.         }
  67.     'MultipleValuesCountry': Result := 0;
  68.         {
  69.           0=Only take first value for Country
  70.           1=Take full list, separated by commas
  71.           2=Take full list, separated by slashes
  72.         }
  73.     'MultipleValuesCategory': Result := 0;
  74.         {
  75.           0=Only take first value for Category
  76.           1=Take full list, separated by commas
  77.           2=Take full list, separated by slashes
  78.         }
  79.     'MultipleValuesLanguages': Result := 0;
  80.         {
  81.           0=Only take first value for Languages
  82.           1=Take full list, separated by commas
  83.           2=Take full list, separated by slashes
  84.         }
  85.     'DescriptionSelection': Result := 2;
  86.         {
  87.           0=Take the short summary, from main page (faster)
  88.           1=Show a list of available summaries
  89.           2=Take the longest summary
  90.         }
  91.     'GetTagline': Result := 0;
  92.         {
  93.           0=Do not get tagline
  94.           1=Put it in Description field, before the summary
  95.           2=Put it in the Comment field, before the comments
  96.         }
  97.   end;
  98. end;
  99.  
  100. // Here you can specify which fields can be modified.
  101. // Simply remove a field from the list if it cannot be modified
  102.  
  103. function CanSetField(fieldID: Integer): Boolean;
  104. begin
  105.   case fieldID of
  106.     fieldNumber,
  107.     fieldMedia,
  108.     fieldMediaType,
  109.     fieldSource,
  110.     fieldDate,
  111.     fieldBorrower,
  112.     fieldRating,
  113.     fieldOriginalTitle,
  114.     fieldTranslatedTitle,
  115.     fieldDirector,
  116.     fieldProducer,
  117.     fieldCountry,
  118.     fieldCategory,
  119.     fieldYear,
  120.     fieldLength,
  121.     fieldActors,
  122.     fieldURL,
  123.     fieldDescription,
  124.     fieldComments,
  125.     fieldVideoFormat,
  126.     fieldVideoBitrate,
  127.     fieldAudioFormat,
  128.     fieldAudioBitrate,
  129.     fieldResolution,
  130.     fieldFrameRate,
  131.     fieldLanguages,
  132.     fieldSubtitles,
  133.     fieldSize,
  134.     fieldDisks:   Result := True;
  135.   else
  136.     Result := False;
  137.   end;
  138. end;
  139.  
  140. var
  141.   MovieName: string;
  142.   MovieURL: string;
  143.   MovieNumber: string;
  144.  
  145. var
  146.   RemainingText: string;
  147.   {
  148.     when calling...     this variable contains...
  149.     TextBefore          the text after SearchText
  150.     TextBetween         the text after AfterText
  151.   }
  152.  
  153. // ***** Like the Pos function, but returns the last occurence instead of the first one *****
  154.  
  155. function LastPos(ASearch: string; AText: string): Integer;
  156. var
  157.   CurPos, PrevPos: Integer;
  158. begin
  159.   PrevPos := 0;
  160.   CurPos := Pos(ASearch, AText);
  161.   while CurPos > 0 do
  162.   begin
  163.     if PrevPos = 0 then
  164.       PrevPos := CurPos
  165.     else
  166.       PrevPos := PrevPos + CurPos + Length(ASearch) - 1;
  167.     Delete(AText, 1, CurPos + Length(ASearch) - 1);
  168.     CurPos := Pos(ASearch, AText);
  169.   end;
  170.   Result := PrevPos;
  171. end;
  172.  
  173. // *****
  174. {    Returns the text before SearchText, but not before BeginLimit (if it is not empty),
  175.     It takes the last occurence of BeginLimit found before the position of SearchText  }
  176.  
  177. function TextBefore(WholeText: string; SearchText: string; BeginLimit: string): string;
  178. var
  179.   FoundPos, PrevPos: Integer;
  180.   WorkText: string;
  181. begin
  182.   Result := '';
  183.   FoundPos := Pos(SearchText, WholeText);
  184.   if FoundPos = 0 then
  185.     Exit;
  186.   WorkText := Copy(WholeText, 1, FoundPos - 1);
  187.   RemainingText := Copy(WholeText, FoundPos + Length(SearchText), Length(WholeText));
  188.   if BeginLimit <> '' then
  189.   begin
  190.     FoundPos := LastPos(BeginLimit, WorkText);
  191.     if FoundPos = 0 then
  192.       Exit
  193.     else
  194.       FoundPos := FoundPos + Length(BeginLimit);
  195.   end
  196.   else
  197.     FoundPos := 1;
  198.   Result := Copy(WorkText, FoundPos, Length(WorkText));
  199. end;
  200.  
  201. // ***** Returns the text after SearchText *****
  202.  
  203. function TextAfter(WholeText: string; SearchText: string): string;
  204. var
  205.   FoundPos: Integer;
  206. begin
  207.   Result := '';
  208.   FoundPos := Pos(SearchText, WholeText);
  209.   if FoundPos = 0 then
  210.     Exit;
  211.   Result := Copy(WholeText, FoundPos + Length(SearchText), Length(WholeText));
  212. end;
  213.  
  214. // *****
  215. {    Returns the text between BeforeText and AfterText (without these two strings),
  216.      It takes the first AfterText occurence found after the position of BeforeText  }
  217.  
  218. function TextBetween(WholeText: string; BeforeText: string; AfterText: string): string;
  219. var
  220.   FoundPos: Integer;
  221.   WorkText: string;
  222. begin
  223.   Result := '';
  224.   FoundPos := Pos(BeforeText, WholeText);
  225.   if FoundPos = 0 then
  226.     Exit;
  227.   WorkText := Copy(WholeText, FoundPos + Length(BeforeText), Length(WholeText));
  228.   FoundPos := Pos(AfterText, WorkText);
  229.   if FoundPos = 0 then
  230.     Exit;
  231.   Result := Copy(WorkText, 1, FoundPos - 1);
  232.   RemainingText := Copy(WorkText, FoundPos + Length(AfterText), Length(WorkText));
  233. end;
  234.  
  235. // ***** analyzes the results page that asks to select a movie from a list *****
  236.  
  237. procedure AnalyzeResultsPage(Address: string);
  238. var
  239.   PageText: string;
  240.   Value: string;
  241. begin
  242.   PageText := GetPage(Address);
  243.   if pos('<title>IMDb', PageText) = 0 then
  244.   begin
  245.     AnalyzeMoviePage(PageText)
  246.   end else
  247.   begin
  248.     if Pos('<b>No Matches.</b>', PageText) > 0 then
  249.     begin
  250.       if GetOption('BatchMode') = 0 then
  251.         ShowMessage('No movie found for this search');
  252.       Exit;
  253.     end;
  254.     PickTreeClear;
  255.     repeat
  256.       Value := TextBefore(PageText, '<ol>', '<b>');
  257.       if Value <> '' then
  258.       begin
  259.         HTMLRemoveTags(Value);
  260.         HTMLDecode(Value);
  261.         PickTreeAdd(Value, '');
  262.       end;
  263.       Value := TextBetween(PageText, '<ol>', '</ol>');
  264.       PageText := RemainingText;
  265.     until not AddMovieTitles(Value);
  266.     Value := TextBefore(PageText, '"><b>more titles</b></a>', '<a href="');
  267.     if Value <> '' then
  268.       PickTreeMoreLink('http://us.imdb.com' + Value);
  269.     if PickTreeExec(Address) then
  270.       AnalyzeResultsPage(Address);
  271.   end;
  272. end;
  273.  
  274. // ***** adds the titles contained in <ol>'s items *****
  275.  
  276. function AddMovieTitles(List: string): Boolean;
  277. var
  278.   Value: string;
  279.   Address: string;
  280. begin
  281.   Result := False;
  282.   Value := TextBetween(List, '<li>', '</li>');
  283.   List := RemainingText;
  284.   while Value <> '' do
  285.   begin
  286.     Address := TextBetween(Value, '<a href="', '">');
  287.     HTMLRemoveTags(Value);
  288.     HTMLDecode(Value);
  289.     PickTreeAdd(Value, 'http://us.imdb.com' + Address);
  290.     Result := True;
  291.     Value := TextBetween(List, '<li>', '</li>');
  292.     List := RemainingText;
  293.   end;
  294. end;
  295.  
  296. // ***** analyzes the page containing movie information *****
  297.  
  298. procedure AnalyzeMoviePage(PageText: string);
  299. var
  300.   Value, Value2, Value3, FullValue: string;
  301. begin
  302.   MovieNumber := TextBetween(PageText, '<input type="hidden" name="arg" value="', '"><input');
  303.   MovieURL := 'http://us.imdb.com/title/tt' + MovieNumber;
  304.   // URL
  305.   if CanSetField(fieldURL) then
  306.     SetField(fieldURL, MovieURL);
  307.   // Original Title & Year
  308.   if CanSetField(fieldOriginalTitle) or CanSetField(fieldYear) then
  309.   begin
  310.     Value := TextBetween(PageText, '<title>', '</title>');
  311.     Value2 := TextBefore(Value, ' (', '');
  312.     Value := RemainingText;
  313.     HTMLDecode(Value2);
  314.     if CanSetField(fieldOriginalTitle) then
  315.       SetField(fieldOriginalTitle, Value2);
  316.     if Pos('/', Value) > 0 then
  317.       Value2 := TextBefore(Value, '/', '')
  318.     else
  319.       Value2 := TextBefore(Value, ')', '');
  320.     if CanSetField(fieldYear) then
  321.       SetField(fieldYear, Value2);
  322.   end;
  323.   // Rating
  324.   if CanSetField(fieldRating) then
  325.   begin
  326.     Value := TextBetween(PageText, '/rating-stars/', '/rating-vote/');
  327.     Value2 := TextBetween(Value, '<b>', '.');
  328.     if StrToInt(Copy(RemainingText, 1, 1), 0) >= 5 then
  329.       Value2 := IntToStr(StrToInt(Value2, 0) + 1);
  330.     SetField(fieldRating, Value2);
  331.   end;
  332.   // Picture
  333.   case GetOption('ImageKind') of
  334.     1:  ImportSmallPicture(PageText);
  335.     2:  if not ImportLargePicture('http://us.imdb.com/gallery/ss/' + MovieNumber) then
  336.           ImportSmallPicture(PageText);
  337.     3:  if not ImportAmazonPicture(PageText) then
  338.           if not ImportLargePicture('http://us.imdb.com/gallery/ss/' + MovieNumber) then
  339.             ImportSmallPicture(PageText);
  340.     4:  if not ImportAmazonPicture(PageText) then
  341.           ImportSmallPicture(PageText);
  342.     5:  if not ImportLargePicture('http://us.imdb.com/gallery/ss/' + MovieNumber) then
  343.           if not ImportAmazonPicture(PageText) then
  344.             ImportSmallPicture(PageText);
  345.   end;
  346.   // Director
  347.   if CanSetField(fieldDirector) then
  348.   begin
  349.     Value := TextBetween(PageText, '<b class="blackcatheader">Directed by</b>', '</a>');
  350.     Value := StringReplace(TextAfter(Value, '">'), '<br>', ', ');
  351.     HTMLRemoveTags(Value);
  352.     HTMLDecode(Value);
  353.     SetField(fieldDirector, Value);
  354.   end;
  355.   // Actors
  356.   if CanSetField(fieldActors) then
  357.   begin
  358.     Value := TextBetween(PageText, 'ast overview', '</div>');
  359.     if Value = '' then
  360.       Value := TextBetween(PageText, 'redited cast', '</div>');
  361.     if Value <> '' then
  362.     begin
  363.       Value := TextAfter(Value, '</tr> ');
  364.       FullValue := '';
  365.       case GetOption('ActorsLayout') of
  366.         0, 1:
  367.           while Pos('<tr>', Value) > 0 do
  368.           begin
  369.             Value2 := TextBetween(Value, '<tr>', '</tr>');
  370.             Value := RemainingText;
  371.             if Pos('<a href="fullcredits">(more)</a>', Value2) > 0 then
  372.               Break;
  373.             if FullValue <> '' then
  374.               FullValue := FullValue + #13#10;
  375.             FullValue := FullValue + TextBefore(Value2, '</td>', '');
  376.           end;
  377.         2, 3:
  378.           while Pos('<tr>', Value) > 0 do
  379.           begin
  380.             Value2 := TextBetween(Value, '<tr>', '</tr>');
  381.             Value := RemainingText;
  382.             if Pos('<a href="fullcredits">(more)</a>', Value2) > 0 then
  383.               Break;
  384.             if FullValue <> '' then
  385.               FullValue := FullValue + #13#10;
  386.             FullValue := FullValue + TextBefore(Value2, '</td>', '');
  387.             Value2 := TextBetween(RemainingText, '<td valign="top">', '</td>');
  388.             if Value2 <> '' then
  389.               FullValue := FullValue + ' (as ' + Value2 + ')';
  390.           end;
  391.         4:
  392.           begin
  393.             FullValue := TextBefore(Value, '</tr><tr><td colspan="2">', '');
  394.             if FullValue = '' then
  395.               FullValue := Value;
  396.             FullValue := StringReplace(FullValue, '</tr>', #13#10);
  397.           end;
  398.       end;
  399.       HTMLRemoveTags(FullValue);
  400.       HTMLDecode(FullValue);
  401.       case GetOption('ActorsLayout') of
  402.         0, 2:
  403.           FullValue := StringReplace(FullValue, #13#10, ', ');
  404.       end;
  405.       SetField(fieldActors, FullValue);
  406.     end;
  407.   end;
  408.   //Country
  409.   if CanSetField(fieldCountry) then
  410.   begin
  411.     SetField(fieldCountry, ImportList(PageText, GetOption('MultipleValuesCountry'), '/Countries/'));
  412.   end;
  413.   //Category
  414.   if CanSetField(fieldCategory) then
  415.   begin
  416.     SetField(fieldCategory, ImportList(PageText, GetOption('MultipleValuesCategory'), '/Genres/'));
  417.   end;
  418.   // Language
  419.   if CanSetField(fieldLanguages) then
  420.   begin
  421.     SetField(fieldLanguages, ImportList(PageText, GetOption('MultipleValuesLanguages'), '/Languages/'));
  422.   end;
  423.   //Description
  424.   if CanSetField(fieldDescription) then
  425.   begin
  426.     Value := TextBetween(PageText, '<b class="ch">Plot Outline:</b>', '<br><br>');
  427.     if Value = '' then
  428.       Value := TextBetween(PageText, '<b class="ch">Plot Summary:</b>', '<br><br>');
  429.     if Value <> '' then
  430.       SetField(fieldDescription, ImportSummary(Value));
  431.   end;
  432.   // Comments
  433.   if CanSetField(fieldComments) then
  434.   begin
  435.     Value := TextAfter(PageText, '/comments">');
  436.     if Value <> '' then
  437.     begin
  438.       Value := TextBetween(Value, '<p>', '</p>');
  439.       Value := StringReplace(Value, #13#10, ' ');
  440.       Value := StringReplace(Value, '<br>', #13#10);
  441.       HTMLRemoveTags(Value);
  442.       HTMLDecode(Value);
  443.       Value := Trim(Value);
  444.       while Pos('  ', Value) > 0 do
  445.         Value := StringReplace(Value, '  ', ' ');
  446.       while Pos(#13#10, Value) = 1 do
  447.         Delete(Value, 1, 2);
  448.       SetField(fieldComments, Value);
  449.     end;
  450.   end;
  451.   // Length
  452.   if CanSetField(fieldLength) then
  453.   begin
  454.     Value := TextBetween(PageText, '<b class="ch">Runtime:</b>' + #13#10, ' ');
  455.     if Value <> '' then
  456.     begin
  457.       if Pos(':', Value) > 0 then
  458.         SetField(fieldLength, TextAfter(Value, ':'))
  459.       else
  460.         SetField(fieldLength, Value);
  461.     end;
  462.   end;
  463.   // TagLine
  464.   if GetOption('GetTagline') > 0 then
  465.   begin
  466.     Value := TextBetween(PageText, 'Tagline:</b>', #13);
  467.     if Pos('<a', Value) > 0 then
  468.       Value := TextBefore(Value, '<a', '');
  469.     HTMLRemoveTags(Value);
  470.     HTMLDecode(Value);
  471.     Value := Trim(Value);
  472.     if Value <> '' then
  473.     begin
  474.       Value := '"' + Value + '"';
  475.       case GetOption('GetTagline') of
  476.         1:
  477.           if CanSetField(fieldDescription) then
  478.             SetField(fieldDescription, Value + #13#10 + GetField(fieldDescription));
  479.         2:
  480.           if CanSetField(fieldComments) then
  481.             SetField(fieldComments, Value + #13#10 + GetField(fieldComments));
  482.       end;
  483.     end;
  484.   end;
  485. end;
  486.  
  487. // ***** Imports lists like Genre, Country, etc. depending of the selected option *****
  488.  
  489. function ImportList(PageText: string; MultipleValues: Integer; StartTag: string): string;
  490. var
  491.   Value, Value2: string;
  492. begin
  493.   if MultipleValues = 0 then
  494.   begin
  495.     Value := TextBetween(PageText, StartTag, '</a>');
  496.     Value2 := TextAfter(Value, '">');
  497.   end
  498.   else
  499.   begin
  500.     Value := TextBetween(PageText, StartTag, #13#10);
  501.     Value2 := TextBefore(Value, ' <a href="/rg', '');
  502.     if Value2 <> '' then
  503.       Value := Value2;
  504.     Value2 := TextAfter(Value, '">');
  505.     HTMLRemoveTags(Value2);
  506.     if MultipleValues = 1 then
  507.       Value2 := StringReplace(Value2, ' / ', ', ');
  508.   end;
  509.   HTMLDecode(Value2);
  510.   Result := Value2;
  511. end;
  512.  
  513. // ***** functions to import the different pictures kinds, depending of the option selected by user *****
  514.  
  515. function ImportSmallPicture(PageText: string): Boolean;
  516. var
  517.   Value: string;
  518. begin
  519.   Result := False;
  520.   Value := TextBetween(PageText, '<img border="0" alt="cover" src="', '"');
  521.   if Value <> '' then
  522.   begin
  523.     GetPicture(Value, False);
  524.     Result := True;
  525.   end;
  526. end;
  527.  
  528. function ImportLargePicture(Address: string): Boolean;
  529. var
  530.   Value, Value2: string;
  531. begin
  532.   Result := True;
  533.   Value := GetPage(Address);
  534.   if SearchForLargePicture(Value, 'Onesheet_text', False) then
  535.     Exit;
  536.   if SearchForLargePicture(Value, 'Onesheet', False) then
  537.     Exit;
  538.   if SearchForLargePicture(Value, 'poster', False) then
  539.     Exit;
  540.   if SearchForLargePicture(Value, 'keyart01', False) then
  541.     Exit;
  542.   if SearchForLargePicture(Value, 'usposter', False) then
  543.     Exit;
  544.   if SearchForLargePicture(Value, 'text', True) then
  545.     Exit;
  546.   if SearchForLargePicture(Value, 'pos01', True) then
  547.     Exit;
  548.   if SearchForLargePicture(Value, 'KeyArt', True) then
  549.     Exit;
  550.   if SearchForLargePicture(Value, 'heet', True) then // Sheet & Onesheet
  551.     Exit;
  552.   if SearchForLargePicture(Value, 'OneSheetv2', True) then
  553.     Exit;
  554.   if SearchForLargePicture(Value, 'artwork', True) then
  555.     Exit;
  556.   Address := TextBetween(Value, 'There are ' + #13#10 + '<a href="', '">');
  557.   if Address <> '' then
  558.     Result := ImportLargePicture('http://us.imdb.com' + Address)
  559.   else
  560.     Result := False;
  561. end;
  562.  
  563. function SearchForLargePicture(PageText: string; Name: string; PartialName: Boolean): Boolean;
  564. var
  565.   Value: string;
  566. begin
  567.   Result := False;
  568.   if PartialName then
  569.   begin
  570.     Value := TextBefore(PageText, Name + '.jpg', '/');
  571.     if Value = '' then
  572.       Exit
  573.     else
  574.       Name := Value + Name;
  575.   end;
  576.   Value := TextBefore(PageText, 'th-' + Name + '.jpg', 'src="');
  577.   if Value <> '' then
  578.   begin
  579.     GetPicture(Value + Name + '.jpg', False);
  580.     Result := True;
  581.   end;
  582. end;
  583.  
  584. function ImportAmazonPicture(PageText: string): Boolean;
  585. var
  586.   Value, Value2: string;
  587. begin
  588.   Result := False;
  589.   Value := TextBefore(PageText, '" title="DVD available', '<a href="');
  590.   if Value = '' then
  591.     Exit;
  592.   PageText := GetPage('http://us.imdb.com' + Value);
  593.   if Pos('unable to find exact matches', PageText) > 0 then
  594.     Exit;
  595.   if Pos('You may also be interested in these items...', PageText) > 0 then
  596.     PageText := TextBefore(PageText, 'You may also be interested in these items...', '');
  597.   Value := TextBefore(PageText, 'TZZZZZZZ.jpg', '<img src="');
  598.   if Value = '' then
  599.     Value := TextBefore(PageText, 'THUMBZZZ.jpg', '<img src="');
  600.   if Value <> '' then
  601.   begin
  602.     GetPicture(Value + 'LZZZZZZZ.jpg', False);
  603.     Result := True;
  604.   end;
  605. end;
  606.  
  607. // ***** Gets summaries for the movie, based on the plot outline given in parameter (that contains the URL to more summaries) *****
  608.  
  609. function ImportSummary(PlotText: string): string;
  610. var
  611.   Address, Value, Value2, PageText, Longest: string;
  612. begin
  613.   Address := TextBetween(PlotText, '<a href="/rg/title-tease/plotsummary', '">(more)</a>');
  614.   if (Address = '') or (GetOption('DescriptionSelection') = 0) then
  615.   begin
  616.     Result := Trim(TextBefore(PlotText, '<a href="/rg', ''));
  617.     if Result = '' then
  618.       Result := Trim(PlotText);
  619.     HTMLRemoveTags(Result);
  620.     HTMLDecode(Result);
  621.   end
  622.   else
  623.   begin
  624.     PageText := GetPage('http://us.imdb.com/rg/title-tease/plotsummary' + Address);
  625.     PickListClear;
  626.     Longest := '';
  627.     Value := TextBetween(PageText, '<p class="plotpar">', '</p>');
  628.     PageText := RemainingText;
  629.     while Value <> '' do
  630.     begin
  631.       Value := StringReplace(Value, #13#10, ' ');
  632.       Value := StringReplace(Value, '<br>', #13#10);
  633.       HTMLRemoveTags(Value);
  634.       HTMLDecode(Value);
  635.       while Pos('  ', Value) > 0 do
  636.         Value := StringReplace(Value, '  ', ' ');
  637.       if Length(Value) > Length(Longest) then
  638.         Longest := Value;
  639.       PickListAdd(Trim(Value));
  640.       Value := TextBetween(PageText, '<p class="plotpar">', '</p>');
  641.       PageText := RemainingText;
  642.     end;
  643.     if (GetOption('BatchMode') = 1) or (GetOption('DescriptionSelection') = 2) then
  644.       Result := Longest
  645.     else
  646.     begin
  647.       if not PickListExec('Select a description for "' + GetField(fieldOriginalTitle) + '"', Result) then
  648.         Result := '';
  649.     end;
  650.   end;
  651. end;
  652.  
  653. // ***** beginning of the program *****
  654.  
  655. begin
  656.   if CheckVersion(3,4,3) then
  657.   begin
  658.     MovieName := GetField(fieldOriginalTitle);
  659.     if MovieName = '' then
  660.       MovieName := GetField(fieldTranslatedTitle);
  661.     if GetOption('BatchMode') = 0 then
  662.     begin
  663.       if not Input('IMDB Import', 'Enter the title or the IMDB URL of the movie:', MovieName) then
  664.         Exit;
  665.     end;
  666.     if MovieName <> '' then
  667.     begin
  668.       if Pos('imdb.com', MovieName) > 0 then
  669.         AnalyzeResultsPage(MovieName)
  670.       else
  671.       begin
  672.         MovieName := StringReplace(MovieName, '&', 'and');
  673.         if (GetOption('BatchMode') = 1) or (GetOption('PopularSearches') = 1) then
  674.           AnalyzeResultsPage('http://us.imdb.com/find?tt=1;q=' + UrlEncode(MovieName))
  675.         else
  676.           AnalyzeResultsPage('http://us.imdb.com/find?more=tt;q=' + UrlEncode(MovieName));
  677.       end;
  678.       DisplayResults;
  679.     end;
  680.   end
  681.   else
  682.     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.3)');
  683. end.
  684.